{% extends "base_content_type.html" %}

{% block fields %}
<li><label for="url">url</label>
<input id="url" name="url" size="100" value="{{ content.url }}"/>
</li>

<li><div id="searchcontrol"><a id="searchaction" class="action">Search?</a></div>
</li>
{% endblock %}

{% block editor_script_extra %}
  var attachHandler = function() {
    $('#searchaction').one('click', function() {
      if (!minerva.webSearchControl) {
        minerva.webSearchControl = new google.search.SearchControl();
        var webSearch = new google.search.WebSearch();
        minerva.webSearchControl.addSearcher(webSearch);
        }

      var elq = $('#searchcontrol');
      minerva.webSearchControl.draw(elq.get(0));
      elq.intercept('click', 'a', function(e) {
        e.preventDefault();
        $('input#url').val(e.target.href);
        });

      });
    }

  if (!google.search) {
    var gopts = {
      'nooldnames': true,
      'language': 'en',
      'callback': attachHandler,
      };
    google.load('search', '1', gopts);
    }
  else {
    attachHandler()
    }
{% endblock %}

{% block attributes %}
{% if embed %}
  <a href="{{ content.url }}">{{ content.title }}</a>
{% else %}
  <iframe class="webpage" src="{{ content.url }}"></iframe>
{% endif %}

{% endblock %}
